package cn.catsdad.vo;

import cn.catsdad.dto.MenuDTO;
import cn.catsdad.dto.UserDTO;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;
import java.util.List;

@Data
public class LoginUser implements UserDetails {

    /**
     * 系统存储用户
     */
    private UserDTO user;

    /**
     * 用户具备的功能项
     */
    private List<MenuDTO> menuList;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 部门id
     */
    private Long departmentId;

    /**
     * 部门名称
     */
    private String departmentName;

    /**
     * token
     */
    private String token;

    /**
     * 登陆时间
     */
    private Long loginTime;

    /**
     * 过期时间
     */
    private Long expireTime;

    public LoginUser(UserDTO user, String token) {
        this(user);
        this.token = token;
    }

    public LoginUser(UserDTO user) {
        if (user != null) {
            this.user = user;
            this.userId = user.getId();
        }
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return null;
    }

    @Override
    public String getPassword() {
        return this.user.getPassword();
    }

    @Override
    public String getUsername() {
        return this.user.getLoginName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
